package com.util;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.regex.Pattern;

public class AppUtils {
	/**
	 * 判断是否为整数
	 * @param str
	 * @return
	 */
	public static boolean isInteger(String str) {    
	    Pattern pattern = Pattern.compile("^[-\\+]?[\\d]*$");    
	    return pattern.matcher(str).matches();    
	}
	
	/**
	 * 日期格式化
	 * @param time
	 * @return
	 */
	public static String dateToString(Date time,String format){ 
	    SimpleDateFormat formatter = new SimpleDateFormat (format); 
	    String ctime = formatter.format(time); 

	    return ctime; 
	} 
	
	/**
	 * 获取当前时间前一天日期
	 * @return
	 */
	public static String getPrevDate(){
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); 
		Calendar cal = Calendar.getInstance(); 
		cal.add(Calendar.DATE, -1); 
		Date date = cal.getTime(); 
		String ctime = df.format(date);
		
//		return ctime;
		return "2017-08-01";
	}
	
	/**
	 * 获取当月
	 * @return
	 */
	public static String getCurrMonth(){
		SimpleDateFormat df = new SimpleDateFormat("yyyyMM"); 
		Calendar cal = Calendar.getInstance(); 
		Date date = cal.getTime(); 
		String ctime = df.format(date);
		
//		return ctime;
		return "201708";
	}
	
	public static void main(String[] args){
//		System.out.println(getCurrMonth());
		String ss = "%";
		ss = ss.substring(0, ss.indexOf("%"));
		System.out.println(ss);
		
	}
}
